/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/{{entities@SQL}}Service.java.hbs
 */
package cn.ibizlab.core.ad.service;

import java.util.*;

import org.springframework.data.domain.Page;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.ibizlab.util.security.SpringContextHolder;
import cn.ibizlab.util.domain.ImportResult;
import cn.ibizlab.core.ad.domain.SysOrganizationalRole;
import cn.ibizlab.core.ad.filter.SysOrganizationalRoleSearchContext;
import cn.ibizlab.core.ad.domain.SysDepartment;
import cn.ibizlab.core.ad.domain.SysOrganizationalUnit;
import cn.ibizlab.core.ad.domain.SysOrganization;
import cn.ibizlab.core.ad.domain.SysMember;
import cn.ibizlab.core.ad.domain.SysGroupOfNames;

/**
 * 用户组服务接口[SysOrganizationalRoleService]
 *
 * @author generator
 */
public interface SysOrganizationalRoleService extends IService<SysOrganizationalRole> {

    /**
     * 获取当前Service
     *
     * @return
     */
    default SysOrganizationalRoleService getSelf() {
        return SpringContextHolder.getBean(this.getClass());
    }

    /**
     * 获取
     * @param et
     * @return
     */
    SysOrganizationalRole get(SysOrganizationalRole et);
    /**
     * 获取
     * @param key
     * @return
     */
    default SysOrganizationalRole get(String key) {
        return getSelf().get(new SysOrganizationalRole().setId(key));
    }
    /**
     * id集合获取
     * @param ids
     * @return
     */
    default List<SysOrganizationalRole> getByIds(Collection<String> ids) {
        List<SysOrganizationalRole> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysOrganizationalRole().setId(key)));
        return getSelf().getByEntities(entities);
    }
    /**
     * 对象集合获取
     * @param entities
     * @return
     */
    List<SysOrganizationalRole> getByEntities(List<SysOrganizationalRole> entities);

    /**
     * 草稿
     * @param et
     * @return
     */
    SysOrganizationalRole getDraft(SysOrganizationalRole et);

    /**
     * checkKey
     * @param et
     * @return
     */
    Integer checkKey(SysOrganizationalRole et);

    /**
     * 创建
     * @param et
     * @return
     */
    boolean create(SysOrganizationalRole et);
    /**
     * 批量创建
     * @param list
     * @return
     */
    boolean createBatch(List<SysOrganizationalRole> list);

    /**
     * 更新
     * @param et
     * @return
     */
    boolean update(SysOrganizationalRole et);
    /**
     * 批量更新
     * @param list
     * @return
     */
    boolean updateBatch(List<SysOrganizationalRole> list);

    /**
     * 保存
     * @param et
     * @return
     */
    @Override
    boolean save(SysOrganizationalRole et);
    /**
     * 批量保存
     * @param list
     * @return
     */
    boolean saveBatch(List<SysOrganizationalRole> list);

    /**
     * 主键删除
     * @param key
     * @return
     */
    default boolean remove(String key) {
        return getSelf().remove(new SysOrganizationalRole().setId(key));
    }
    /**
     * 根据keys批量删除
     * @param keys
     * @return
     */
    default boolean remove(List<String> keys) {
        return removeBatch(keys);
    }
    /**
     * 根据对象删除
     * @param et
     * @return
     */
    boolean remove(SysOrganizationalRole et);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    default boolean removeBatch(Collection<String> ids) {
        List<SysOrganizationalRole> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysOrganizationalRole().setId(key)));
        return getSelf().removeByEntities(entities);
    }

    /**
     * 批量删除对象
     * @param entities
     * @return
     */
    boolean removeByEntities(List<SysOrganizationalRole> entities);

    default ImportResult importData(String config, Boolean ignoreError, List<SysOrganizationalRole> list) {
        ImportResult rt = new ImportResult().setTotal(list.size());
        for(int i=0;i<list.size();i++) {
            SysOrganizationalRole et=list.get(i);
            try {
                this.getSelf().save(et);
                rt.setSuccess(rt.getSuccess()+1);
            }catch (Exception ex){
                rt.addItem(i+1,et.getName(),ex.getMessage());
                if(!ignoreError)
                    break;
            }
        }
        return rt;
    }

    /**
     * RoleAuth
     * 批量授权系统角色
     * @param dto
     * @return
     */
    default SysOrganizationalRole roleAuth(SysOrganizationalRole dto) {
        return dto;
    }

    /**
     * searchCurPersonGroup
     * 
     * @param context
     * @return
     */
    Page<SysOrganizationalRole> searchCurPersonGroup(SysOrganizationalRoleSearchContext context);
    /**
     * listCurPersonGroup
     * 
     * @param context
     * @return
     */
    List<SysOrganizationalRole> listCurPersonGroup(SysOrganizationalRoleSearchContext context);

    /**
     * searchDefault
     * 
     * @param context
     * @return
     */
    Page<SysOrganizationalRole> searchDefault(SysOrganizationalRoleSearchContext context);
    /**
     * listDefault
     * 
     * @param context
     * @return
     */
    List<SysOrganizationalRole> listDefault(SysOrganizationalRoleSearchContext context);

    /**
     * 创建实体对象
     * @return
     */
    default SysOrganizationalRole getEntity() {
        return new SysOrganizationalRole();
    }
    /**
     * 创建搜索对象
     * @return
     */
    default SysOrganizationalRoleSearchContext getSearchContext() {
        return new SysOrganizationalRoleSearchContext();
    }
    /**
     * selectRelByDepartmentId
     * @param departmentIds
     * @return
     */
    List<SysOrganizationalRole> findByDepartmentId(List<String> departmentIds);
    default List<SysOrganizationalRole> findByDepartmentId(String departmentId) {
        return findByDepartmentId(Arrays.asList(departmentId));
    }
    /**
     * removeRelByDepartmentId
     * @param departmentId
     * @return
     */
    boolean removeByDepartmentId(String departmentId);
    /**
     * resetRelByDepartmentId
     * @param departmentId
     * @return
     */
    boolean resetByDepartmentId(String departmentId);
    /**
     * saveRelByDepartment
     * @param sysDepartment
     * @param list
     * @return
     */
    boolean saveByDepartment(SysDepartment sysDepartment,List<SysOrganizationalRole> list);
    /**
     * saveRelByDepartmentId
     * @param departmentId
     * @param list
     * @return
     */
    default boolean saveByDepartmentId(String departmentId,List<SysOrganizationalRole> list) {
        return getSelf().saveByDepartment(new SysDepartment().setId(departmentId),list);
    }

    /**
     * selectRelByOrganizationalUnitId
     * @param organizationalUnitIds
     * @return
     */
    List<SysOrganizationalRole> findByOrganizationalUnitId(List<String> organizationalUnitIds);
    default List<SysOrganizationalRole> findByOrganizationalUnitId(String organizationalUnitId) {
        return findByOrganizationalUnitId(Arrays.asList(organizationalUnitId));
    }
    /**
     * removeRelByOrganizationalUnitId
     * @param organizationalUnitId
     * @return
     */
    boolean removeByOrganizationalUnitId(String organizationalUnitId);
    /**
     * resetRelByOrganizationalUnitId
     * @param organizationalUnitId
     * @return
     */
    boolean resetByOrganizationalUnitId(String organizationalUnitId);
    /**
     * saveRelByOrganizationalUnit
     * @param sysOrganizationalUnit
     * @param list
     * @return
     */
    boolean saveByOrganizationalUnit(SysOrganizationalUnit sysOrganizationalUnit,List<SysOrganizationalRole> list);
    /**
     * saveRelByOrganizationalUnitId
     * @param organizationalUnitId
     * @param list
     * @return
     */
    default boolean saveByOrganizationalUnitId(String organizationalUnitId,List<SysOrganizationalRole> list) {
        return getSelf().saveByOrganizationalUnit(new SysOrganizationalUnit().setId(organizationalUnitId),list);
    }

    /**
     * selectRelByOrganizationId
     * @param organizationIds
     * @return
     */
    List<SysOrganizationalRole> findByOrganizationId(List<String> organizationIds);
    default List<SysOrganizationalRole> findByOrganizationId(String organizationId) {
        return findByOrganizationId(Arrays.asList(organizationId));
    }
    /**
     * removeRelByOrganizationId
     * @param organizationId
     * @return
     */
    boolean removeByOrganizationId(String organizationId);
    /**
     * resetRelByOrganizationId
     * @param organizationId
     * @return
     */
    boolean resetByOrganizationId(String organizationId);
    /**
     * saveRelByOrganization
     * @param sysOrganization
     * @param list
     * @return
     */
    boolean saveByOrganization(SysOrganization sysOrganization,List<SysOrganizationalRole> list);
    /**
     * saveRelByOrganizationId
     * @param organizationId
     * @param list
     * @return
     */
    default boolean saveByOrganizationId(String organizationId,List<SysOrganizationalRole> list) {
        return getSelf().saveByOrganization(new SysOrganization().setId(organizationId),list);
    }

    default List<SysMember> getMember(SysOrganizationalRole et) {
        return new ArrayList<>();
    }


    /**
     * 自定义查询SQL
     * @param sql  select * from table where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    List<JSONObject> select(String sql, Map<String,Object> param);

    /**
     * 自定义SQL
     * @param sql  update table  set name ='test' where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    boolean execute(String sql, Map<String,Object> param);

}